package com.yunyan.controller;

import com.yunyan.entity.UserData;
import com.yunyan.resp.JsonResp;
import com.yunyan.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {



    @Resource
    private UserService userService;

    @PostMapping("/register")
    public JsonResp register(@RequestBody UserData userData){
        return JsonResp.ok(userService.register(userData));
    }

    @PostMapping("/login")
    public JsonResp login(@RequestBody UserData userData){
        return JsonResp.ok(userService.login(userData));
    }


    // 获取用户信息
    @GetMapping("/{userId}")
    public JsonResp profile(@PathVariable String userId){
        return JsonResp.ok(userService.getById(userId));
    }


    // 更新用户信息
    @PutMapping
    public JsonResp update(@RequestBody UserData userData){
        return JsonResp.ok(userService.updateById(userData));
    }
}
